﻿USE [AspectDemo]
GO
/****** Object:  ForeignKey [FK_SalesOrder_Customer]    Script Date: 03/07/2009 19:30:56 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_SalesOrder_Customer]') AND parent_object_id = OBJECT_ID(N'[dbo].[SalesOrder]'))
ALTER TABLE [dbo].[SalesOrder] DROP CONSTRAINT [FK_SalesOrder_Customer]
GO
/****** Object:  ForeignKey [FK_SalesOrderLine_Product]    Script Date: 03/07/2009 19:30:56 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_SalesOrderLine_Product]') AND parent_object_id = OBJECT_ID(N'[dbo].[SalesOrderLine]'))
ALTER TABLE [dbo].[SalesOrderLine] DROP CONSTRAINT [FK_SalesOrderLine_Product]
GO
/****** Object:  ForeignKey [FK_SalesOrderLine_SalesOrder]    Script Date: 03/07/2009 19:30:56 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_SalesOrderLine_SalesOrder]') AND parent_object_id = OBJECT_ID(N'[dbo].[SalesOrderLine]'))
ALTER TABLE [dbo].[SalesOrderLine] DROP CONSTRAINT [FK_SalesOrderLine_SalesOrder]
GO
/****** Object:  Table [dbo].[SalesOrderLine]    Script Date: 03/07/2009 19:30:56 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SalesOrderLine]') AND type in (N'U'))
DROP TABLE [dbo].[SalesOrderLine]
GO
/****** Object:  Table [dbo].[SalesOrder]    Script Date: 03/07/2009 19:30:56 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SalesOrder]') AND type in (N'U'))
DROP TABLE [dbo].[SalesOrder]
GO
/****** Object:  Table [dbo].[Product]    Script Date: 03/07/2009 19:30:56 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Product]') AND type in (N'U'))
DROP TABLE [dbo].[Product]
GO
/****** Object:  Table [dbo].[Customer]    Script Date: 03/07/2009 19:30:56 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Customer]') AND type in (N'U'))
DROP TABLE [dbo].[Customer]
GO
/****** Object:  Table [dbo].[Product]    Script Date: 03/07/2009 19:30:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Product]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Product](
	[ProductID] [int] IDENTITY(1,1) NOT NULL,
	[ProductName] [varchar](50) NOT NULL,
 CONSTRAINT [PK_Product] PRIMARY KEY CLUSTERED 
(
	[ProductID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Customer]    Script Date: 03/07/2009 19:30:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Customer]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Customer](
	[CustomerID] [int] IDENTITY(1,1) NOT NULL,
	[CustomerName] [varchar](50) NULL,
 CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED 
(
	[CustomerID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[SalesOrderLine]    Script Date: 03/07/2009 19:30:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SalesOrderLine]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[SalesOrderLine](
	[SalesOrderLineID] [int] IDENTITY(1,1) NOT NULL,
	[SalesOrderID] [int] NOT NULL,
	[ProductID] [int] NOT NULL,
	[Quantity] [decimal](18, 9) NOT NULL,
 CONSTRAINT [PK_SalesOrderLine] PRIMARY KEY CLUSTERED 
(
	[SalesOrderLineID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[SalesOrder]    Script Date: 03/07/2009 19:30:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SalesOrder]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[SalesOrder](
	[SalesOrderID] [int] IDENTITY(1,1) NOT NULL,
	[CustomerID] [int] NOT NULL,
	[OrderDate] [datetime] NOT NULL,	
	[CreateDate] [datetime] NOT NULL CONSTRAINT [DF_SalesOrder_OrderDate]  DEFAULT (getdate()),
 CONSTRAINT [PK_SalesOrder] PRIMARY KEY CLUSTERED 
(
	[SalesOrderID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  ForeignKey [FK_SalesOrder_Customer]    Script Date: 03/07/2009 19:30:56 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_SalesOrder_Customer]') AND parent_object_id = OBJECT_ID(N'[dbo].[SalesOrder]'))
ALTER TABLE [dbo].[SalesOrder]  WITH CHECK ADD  CONSTRAINT [FK_SalesOrder_Customer] FOREIGN KEY([CustomerID])
REFERENCES [dbo].[Customer] ([CustomerID])
GO
ALTER TABLE [dbo].[SalesOrder] CHECK CONSTRAINT [FK_SalesOrder_Customer]
GO
/****** Object:  ForeignKey [FK_SalesOrderLine_Product]    Script Date: 03/07/2009 19:30:56 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_SalesOrderLine_Product]') AND parent_object_id = OBJECT_ID(N'[dbo].[SalesOrderLine]'))
ALTER TABLE [dbo].[SalesOrderLine]  WITH CHECK ADD  CONSTRAINT [FK_SalesOrderLine_Product] FOREIGN KEY([ProductID])
REFERENCES [dbo].[Product] ([ProductID])
GO
ALTER TABLE [dbo].[SalesOrderLine] CHECK CONSTRAINT [FK_SalesOrderLine_Product]
GO
/****** Object:  ForeignKey [FK_SalesOrderLine_SalesOrder]    Script Date: 03/07/2009 19:30:56 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_SalesOrderLine_SalesOrder]') AND parent_object_id = OBJECT_ID(N'[dbo].[SalesOrderLine]'))
ALTER TABLE [dbo].[SalesOrderLine]  WITH CHECK ADD  CONSTRAINT [FK_SalesOrderLine_SalesOrder] FOREIGN KEY([SalesOrderID])
REFERENCES [dbo].[SalesOrder] ([SalesOrderID])
GO
ALTER TABLE [dbo].[SalesOrderLine] CHECK CONSTRAINT [FK_SalesOrderLine_SalesOrder]
GO
